package org.itcast.travel.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.itcast.travel.mapper.TicketMapper;
import org.itcast.travel.pojo.*;
import org.itcast.travel.service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Component
@Service
public class TicketServiceImpl implements TicketService {
    @Autowired
    private TicketMapper ticketMapper;
    @Override
    //购票
    public void save(Ticket ticket) {
        ticket.setCreateTime(LocalDateTime.now());
        ticket.setUpdateTime(LocalDateTime.now());
        ticketMapper.save(ticket);

    }

    @Override
    //删除
    public void deleteById(List<Integer> ids) {
        ticketMapper.deleteById(ids);
    }
    //查询回显
    @Override
    public Ticket getById(Integer id) {
        Ticket ticket = ticketMapper.getById(id);
        if (ticket!=null){
            return ticket;
        }
        return null;
    }
    //修改
    @Override
    public void update(Ticket ticket) {
        ticket.setUpdateTime(LocalDateTime.now());
        ticketMapper.update(ticket);


    }

    @Override
    public PageBean page(TicketQueryParam ticketQueryParam) {
        //设置分页参数
        PageHelper.startPage(ticketQueryParam.getPage(),ticketQueryParam.getPageSize());
        //查询分页数据
        Page<TicketVO> page= ticketMapper.page(ticketQueryParam);
        //解析封装分页的结果
        return new PageBean(page.getTotal(),page.getResult());
    }
}
